﻿using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
@TestRunner.Imports


namespace @Test.Namespace
{
	
	public partial class @Test.ClassName
	{


@{
 
    foreach (var itemType in Class.ListT.Where(t => t.IsCreatable))
    { 

        <text>

        @Tag("IList")
        @Tag("Memory")
		@TestAttribute
        public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_AddClear_Memory") ()
		{
			IList<@itemType.FullName> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

			Func<WeakReference> run = () =>
			{
				@itemType.FullName newItem;

				try
				{
					newItem = @itemType.GetConstructorCode();
					objectUnderTest.Add(newItem);
					return new WeakReference(newItem);
				}
				catch (ArgumentException)
				{
					return null;
				}            
			};

			var wr = run();
			if (wr == null)
				return; //test inconclusive

			//release strong references
			objectUnderTest.Clear();
			
            GC.Collect();
			GC.WaitForPendingFinalizers();
			GC.Collect();

			//verify the object was collected
			Assert.IsFalse(wr.IsAlive);

		}


        @Tag("IList")
        @Tag("Memory")
        @TestAttribute
        public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_AddRemove_Memory") ()
		{
			IList<@itemType.FullName> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            var oldCount = objectUnderTest.Count;
            
			Func<WeakReference> run = () =>
			{
				@itemType.FullName newItem;

				try
				{
					newItem = @itemType.GetConstructorCode();
					objectUnderTest.Add(newItem);
					return new WeakReference(newItem);
				}
				catch (ArgumentException)
				{
					return null;
				}            
			};

			var wr = run();
			if (wr == null)
				return; //test inconclusive

			//release strong references
			Action run2 = () => {
				objectUnderTest.Remove((@itemType.FullName)wr.Target);
			};
			
			run2();

            GC.Collect();
			GC.WaitForPendingFinalizers();
			GC.Collect();

			//verify the object was collected
			Assert.IsFalse(wr.IsAlive);		
        }

        @Tag("IList")
        @Tag("Memory")
        @TestAttribute
        public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_AddRemoveAt_Memory") ()
		{
			IList<@itemType.FullName> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

			Func<WeakReference> run = () =>
			{
				@itemType.FullName newItem;

				try
				{
					newItem = @itemType.GetConstructorCode();
					objectUnderTest.Add(newItem);
					return new WeakReference(newItem);
				}
				catch (ArgumentException)
				{
					return null;
				}            
			};

			var wr = run();
			if (wr == null)
				return; //test inconclusive

			//release strong references
			//release strong references
			Action run2 = () => {
				var newIndex = objectUnderTest.IndexOf((@itemType.FullName)wr.Target);
				objectUnderTest.RemoveAt(newIndex);
			};
			
			run2();
			
            GC.Collect();
			GC.WaitForPendingFinalizers();
			GC.Collect();

			//verify the object was collected
			Assert.IsFalse(wr.IsAlive);		
		}


        </text>
    }
    
    
 }
	}
}

